@extends('layouts.app')

@section('content')
<div class="content order content_import">
	<div class="button">
		<span class="business">
			@if(count($business) == 1)
			<label>所有商家</label><i></i>
			<ul>
				<li data-activity="{{ json_encode($business[0]->activitys->load(['types'=>function($query) use ($business){
					return $query->where('business_id',$business[0]->id);
				}])->toArray()) }}" business="{{$business[0]->id}}">{{$business[0]->name}}</li>
			</ul>
			@else
			<label>所有商家</label><i></i>
			<ul>
				@foreach($business as $item)
				<li data-activity="{{ json_encode($item->activitys->load(['types'=>function($query) use ($item){
					return $query->where('business_id',$item->id);
				}])->toArray()) }}">{{$item->name}}</li>
				@endforeach
			</ul>
			@endif
		</span>
		<span class="activity">
			<label>所有活动</label><i></i>
			<ul>
			</ul>
		</span>
		<span class="channel">
			<label>所有渠道</label><i></i>
			<ul>
			</ul>
		</span>
		<label for="">订单时间：</label>
		<input id="start" type="text" placeholder="开始时间" readonly>
		<input id="end" type="text" placeholder="结束时间" readonly>
		<span class="order_type" data-type="order_id" style="margin-right: 0;border-radius:4px 0 0 4px;"><label>订单号</label><i></i>
			<ul>
				<li data-type="order_id">订单号</li>
				<li data-type="phone">手机号</li>
				<li data-type="contacts">联系人</li>
			</ul>
		</span><input class="order" type="text"><button onclick="search(this)">搜索</button>
		<p>统计：当前已发货订单数为<label for="" id="sendOrderNum">0</label>个，代发货订单数为<span id="orderNum">0</span>个。</p>
	</div>
	<table>
		<thead>
			<tr>
				<th>序号</th><th>订单号</th><th>商品</th>
				<th>联系人</th><th>手机号</th><th>订单生成时间</th><th>状态</th><th>操作</th>
			</tr>
		</thead>
		<tbody id="list">
		</tbody>
	</table>
	<div class="page_item">
		<div class="page_num">
			<label for="" class="active">10</label>
			<label for="">30</label>
			<label for="">50</label>
		</div>
		<ul class="pagination" id="page1">
		</ul>
		<div class="pageJump">
			<span>跳转到</span>
			<input type="text"/>
			<span>页</span>
			<button type="button" class="button">确定</button>
		</div>
	</div>
</div>
@endsection

@section('scripts')
<script type="text/javascript">
	var baseUrl = "sendOrders";

	params['page'] = 1;
	params['pageSize'] = 10;

	getList(baseUrl,params);
	//订单导入时间插件
	var start = {
		elem: '#start',
		format: 'YYYY-MM-DD',
		max: '2099-06-16', //最大日期
		istime: false,
		istoday: false,
		choose: function(datas){
		    end.min = datas; //开始日选好后，重置结束日的最小日期
		    end.start = datas //将结束日的初始值设定为开始日
		}
	};
	var end = {
		elem: '#end',
		format: 'YYYY-MM-DD',
		max: '2099-06-16',
		istime: false,
		istoday: false,
		choose: function(datas){
		    start.max = datas; //结束日选好后，重置开始日的最大日期
		}
	};
	laydate(start);
	laydate(end);

	$(function(){
		$('.page_item>.page_num>label').click(function(){
			params['pageSize'] = $('.page_num').find('.active').text();
			getList(baseUrl,params);
		})
	})

	if ($('._see').text()=='立即发货') {
		$('._see').css('color','red');
	}
	function search(_this) {
		var business=$(_this).parents('.button').find('.business').attr('business');
		var activity=$(_this).parents('.button').find('.activity').attr('activity');
		var map=$(_this).parents('.button').find('.channel').attr('map');
		var start_time=$(_this).parents('.button').find('#start').val();
		var end_time=$(_this).parents('.button').find('#end').val();
		var searchKey=$(_this).parents('.button').find('.order_type').attr('data-type');
		var searchValue=$(_this).parents('.button').find('.order').val();
		params.business = business ? business : '';
		params.activity = activity ? activity : '';
		params.map = map ? map : '';
		params.start_time = start_time ? start_time : '';
		params.end_time = end_time ? end_time : '';
		params.searchKey = searchKey ? searchKey : '';
		params.searchValue = searchValue ? searchValue : '';
		getList(baseUrl,params);
	}
</script>
@endsection
